﻿namespace Chap4Demo
{
    internal class Program
    {
        static void Main(string[] args)
        {
            //Guy guy1 = new Guy() { Cash = 50, Name = "Joe" };
            //Guy guy2 = new Guy() { Cash = 100, Name = "Bob" };
            //guy1 = guy2;
            //Console.WriteLine("Hello, World!");
            //int first;
            //int second = (first = 10);
            //Console.WriteLine(first);
            //Console.WriteLine(second);








            Elephant lucinda = new Elephant() { Name = "Lucinda", EarSize = 33 };
            Elephant lloyd = new Elephant() { Name = "Lloyd", EarSize = 40 };

            Console.WriteLine("Press 1 for Lloyd,2 for Lucinda,3 to swao");

            while (true)
            {
                char input = Console.ReadKey(true).KeyChar;
                Console.WriteLine("You pressed " + input);
                if (input == '1')
                {
                    Console.WriteLine("Calling lloyd.WhoAmI()");
                    lloyd.WhoAmI();
                }
                else if (input == '2')
                {
                    Console.WriteLine("Calling Lucinda.WhoAmI()");
                    lucinda.WhoAmI();
                }
                else if (input == '3')
                {
                    Elephant holder;
                    holder = lloyd;
                    lloyd = lucinda;
                    lucinda = holder;
                    Console.WriteLine("References have been swapped");
                }
                else if(input == '5')
                {
                    lucinda.SpeekTo(lloyd, "Hi Lloyd!!!");
                }
                else return;
                Console.WriteLine();
            }
        }
    }



    class Guy
    {
        public int Cash;
        public string Name;

        public void WriteMyInfo()
        {
            Console.WriteLine(Name + " has " + Cash + " bucks.");
        }

        public int GiveCash(int amount)
        {
            if (amount <= 0)
            {
                Console.WriteLine($"{Name} says: {amount} isn't a valid amount");
                return 0;
            }
            if (amount > Cash)
            {
                Console.WriteLine($"{Name} says: I don't have enough cash to give you {amount}");
                return 0;
            }
            Cash -= amount;
            return amount;
        }

        public void ReceiveCash(int amount)
        {
            if (amount < 0)
            {
                Console.WriteLine($"{Name} says: {amount} isn't an amount I'll take");
            }
            else
            {
                Cash += amount;
            }
        }

    }
}
